package org.dja.nzw.discovery;

import org.dja.nzw.discovery.domain.Connector;
import org.dja.nzw.discovery.domain.InstanceDetails;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by shuyun on 2016/7/18.
 */
public class Test {
    public static void main(String[] args) throws Exception{
        String serviceName = "JustTest";

        DiscoveryClient client = DiscoveryManager.create("192.168.236.128:2181");

        InstanceDetails instance = new InstanceDetails();
        instance.setName(serviceName);
        instance.setStatus(InstanceDetails.Status.UP);
        instance.setHost("172.0.0.1");
        instance.setEnviroment("base");

        List<Connector> connectors = new ArrayList<Connector>();
        Connector connector = new Connector();
        connector.setPort(8181);
        connector.setSchema("http");
        connector.setUsage("");
        connectors.add(connector);

        instance.setConnectors(connectors);

        client.registerService(instance);

        Thread.sleep(5000);

        List<InstanceDetails> instances = client.applications(serviceName);

        if(null != instances && instances.size() > 0) {
            for (InstanceDetails ins : instances) {
                System.out.println(ins.getHost() + "  -  " + ins.getEnviroment() + "  -  " + ins.getStatus());
            }
        }

        Thread.sleep(5000);

//        client.shutdown();

        while (true){
            System.out.println("alive");
        }
    }
}
